const BYTES_PER_PACKET = 72;
export const PACKETS_PER_MB = 15000;

const calcZoomeyeRate = packetsOrigin => {
  const packets = Number(packetsOrigin);
  if (isNaN(packets)) {
    return '0Kb/s';
  }
  const flow = ((BYTES_PER_PACKET * packets) / 1024).toFixed(2);
  if (packets < PACKETS_PER_MB) {
    return `${flow}Kb/s`;
  } else {
    return `${(flow / 1024).toFixed(2)}Mb/s`;
  }
};

export default calcZoomeyeRate;
